<?php 
/* ================================================================================
 * Events Calendar 
 *
 * main.php: This is the main file for Living Web.
 *
 * Author: Eric Hendrickson (enhendrickson@liberty.edu)
 * Date: 7/20/06
   ================================================================================ */
	
	global $SSO, $Security, $AppID, $User, $DB;
	//Check to see if there is a valid session 
	$SessionInfo = $SSO->isValidSession("index.php?action=login", $SSO->getSessionInformation());	
	
	//Check to see if the user has rights to be on LivingWeb
	$PageRights = array('ADMIN');
	$UserRoles = $Security->ValidateUser($SessionInfo['username'], $AppID, $PageRights, 1);
		
	//Grab the user info
	$UserInfo = $User->GetUserInfo($SessionInfo['username']);	
	
	if(!isset($mode)) {
		$mode = "New";
	}
?>
<script language="javascript" src="/CommonClientScripts/dcl/choosedate.js"></script>
<link type="text/css" rel="stylesheet" href="/CommonClientScripts/dcl/calendar.css">

<table cellpadding="0" cellspacing="0" width="100%" border="0">
	<tr>
		<td>
		<form action="index.php?id=<?php print $_GET['id'];?>&action=<?php print strtolower($mode);?>" method="post" name="frmNewEvent">
			<table cellpadding="0" cellspacing="3" border="0" width="100%" >
				<tr>
					<td><span class="TB1">Title</span></td>
					<td>
						<input class="T1" name="txtEventTitle" type="text" maxlength="100" value="<?php if(isset($row['event_title'])) { print $row['event_title']; }  ?>">
					</td>
				</tr>
				<tr>
					<td><span class="TB1">Start Date/Time</span></td>
					<td valign="middle">
						<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td>
									<input type="text" id="start_calendar" name="start_calendar" readonly style="width:70px;" value="<?php if(isset($row['event_start_date'])) { print substr($row['event_start_date'],0,10); } ?>">
                    &nbsp;
                    <script language="javascript">
                      var basicCal = new calendar("FIELD:document.frmNewEvent.start_calendar;FORMAT:2;DELIMITER:-;");
                      basicCal.writeCalendar();
                    </script>
								</td>
                <td>&nbsp;&nbsp;/&nbsp;&nbsp;</td>
                <td><input type="text" id="start_time" name="start_time" style="width:70px;" value="<?php if(isset($row['event_start_date'])) { print substr($row['event_start_date'],11,8); } ?>">&nbsp;(24 Hour Time)</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td><span class="TB1">End Date/Time</span></td>
					<td valign="middle">
						<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td>
									<input type="text" id="end_calendar" name="end_calendar" readonly style="width:70px;" value="<?php if(isset($row['event_end_date'])) { print substr($row['event_end_date'],0,10); } ?>">
                    &nbsp;
                    <script language="javascript">
                      var basicCal = new calendar("FIELD:document.frmNewEvent.end_calendar;FORMAT:2;DELIMITER:-;");
                      basicCal.writeCalendar();
                    </script>
								</td>
                <td>&nbsp;&nbsp;/&nbsp;&nbsp;</td>
                <td><input type="text" id="end_time" name="end_time" style="width:70px;" value="<?php if(isset($row['event_end_date'])) { print substr($row['event_end_date'],11,8); } ?>">&nbsp;(24 Hour Time)</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td><span class="TB1">Description</span></td>
					<td>
						<input class="T1" name="txtEventDescription" type="text" maxlength="100" size="40" value=<?php if(isset($row['event_description'])) { print $row['event_description']; } ?>>
					</td>
				</tr>
				<tr>
					<td><span class="TB1">Location</span></td>
					<td>
						<input class="T1" name="txtEventLocation" type="text" maxlength="100" value="<?php if(isset($row['event_location'])) { print $row['event_location']; } ?>">
					</td>
				</tr>
				<tr>
				</tr>
			</table>
		</td>
    <td>
      <input  name="btnSubmit" type="submit" class="B" value="<?php print $mode; ?>" style="width:100px;height:100px;font-size:16px;"></form>
    </td>
	</tr>
	<tr>
		<td style="border-top:1px dashed #d8da85;" colspan="2"><br>
			<table cellpadding="5" cellspacing="0" width="100%"> 
				<tr>
					<td><span class="TB1">Title</span></td>
					<td><span class="TB1">Date/Times</span></td>
					<td><span class="TB1">Description</span></td>
					<td><span class="TB1">Location</span></td>
				</tr>
				<?php
				global $DB;
				$DB->query("select * from calendar_events order by event_start_date");
				while($row = $DB->fetch_row())
				{
					print "<tr>";
					print '<td valign="top"><span class="T1">' . $row['event_title'] . '</span></td>';
					print '<td valign="top"><span class="T1">' . date("F d, Y g:i A",strtotime($row['event_start_date'])) . '<br>' . date("F d, Y g:i A",strtotime($row['event_end_date'])) . '</span></td>';
					print '<td valign="top"><span class="T1">' . $row['event_description'] . '</span></td>';
					print '<td valign="top"><span class="T1">' . $row['event_location'] . '</span></td>';
					print '<td valign="top"><a class="L0" href="index.php?action=edit&id=' . $row['event_id'] . '">[edit]</a></td>';
					print '<td valign="top"><a class="L0" href="index.php?action=delete&id=' . $row['event_id'] . '" onClick="if(confirm(\'Are you sure you would like to delete?\')){return true;}else{return false;}">[delete]</a></td>';
					print "</tr>";
				}
				?>
			</table>
		</td>
	</tr>
</table>